<template>
  <a
    v-if="!friend.isApply"
    :href="friend.url"
    target="_blank"
    rel="noopener noreferrer"
    class="friend-card"
  >
    <div class="friend-avatar">
      <img :src="friend.avatar" :alt="friend.name" loading="lazy" />
    </div>
    <div class="friend-info">
      <div class="friend-name">{{ friend.name }}</div>
      <div class="friend-desc">{{ friend.description }}</div>
    </div>
  </a>
  <div v-else class="friend-card apply-card" @click="$emit('apply')">
    <div class="apply-icon">
      <i class="ri-add-line"></i>
    </div>
    <div class="friend-info">
      <div class="friend-name">申请友链</div>
      <div class="friend-desc">添加您的博客到这里</div>
    </div>
  </div>
</template>

<script setup>
defineProps({
  friend: {
    type: Object,
    required: true,
  },
})

defineEmits(['apply'])
</script>

<style lang="scss" scoped>
.friend-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  border-radius: 12px;
  background: var(--bg-base);
  border: 1px solid var(--border-lighter);
  text-decoration: none;
  transition: var(--transition-base);
  cursor: pointer;

  &:hover {
    transform: translateY(-4px);
    border-color: var(--color-primary);
    box-shadow: var(--shadow-light);
    background: var(--bg-hover);

    .friend-avatar {
      img {
        transform: scale(1.1);
      }
    }

    .friend-name {
      color: var(--color-primary);
    }
  }

  &.apply-card {
    border: 2px dashed var(--border-base);
    background: var(--bg-light);

    &:hover {
      border-color: var(--color-primary);
      background: rgba(81, 138, 255, 0.05);

      .apply-icon {
        background: var(--color-primary);
        color: #fff;
      }

      .friend-name {
        color: var(--color-primary);
      }
    }

    .apply-icon {
      width: 56px;
      height: 56px;
      border-radius: 12px;
      background: var(--bg-base);
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      transition: var(--transition-base);
      color: var(--color-primary);
      font-size: 28px;
    }
  }

  .friend-avatar {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    overflow: hidden;
    flex-shrink: 0;
    border: 2px solid var(--border-lighter);
    transition: var(--transition-base);

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      transition: var(--transition-base);
    }
  }

  .friend-info {
    flex: 1;
    min-width: 0;

    .friend-name {
      font-size: 16px;
      font-weight: 600;
      color: var(--text-primary);
      margin-bottom: 6px;
      transition: var(--transition-base);
    }

    .friend-desc {
      font-size: 14px;
      color: var(--text-regular);
      line-height: 1.5;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }
  }
}

@media (max-width: 768px) {
  .friend-card {
    padding: 16px;
    gap: 12px;

    .friend-avatar,
    .apply-icon {
      width: 48px;
      height: 48px;
    }

    .friend-info {
      .friend-name {
        font-size: 15px;
      }

      .friend-desc {
        font-size: 13px;
      }
    }
  }
}
</style>
